<?php

require_once dirname(__FILE__).'/../lib/libroGeneratorConfiguration.class.php';
require_once dirname(__FILE__).'/../lib/libroGeneratorHelper.class.php';

/**
 * libro actions.
 *
 * @package    biblioteca
 * @subpackage libro
 * @author     Ignacio Calvo
 * @version    SVN: $Id: actions.class.php 12474 2008-10-31 10:41:27Z fabien $
 */
class libroActions extends autoLibroActions
{


  public function executeIndex(sfWebRequest $request)
  {
    parent::executeIndex($request);

    $this->lugares = Doctrine::getTable('Lugar')->createQuery()->execute();
    $this->getLogger()->info(count($this->lugares));
  }

  public function executeBatchPlaceLibros(sfWebRequest $request) {
    $ids = $request->getParameter('ids');
    $codigoLugar = $request->getParameter('lugarCode');
    $conn = Doctrine_Manager::connection();
    $conn->beginTransaction();
    $librosEscogidos = Doctrine::getTable('Libro')
      ->createQuery('l')
      ->whereIn('l.id', $ids)
      ->execute();
    foreach ($librosEscogidos as $libro) {
      $libro->setLugarId($codigoLugar);
      $libro->save();
    }
    $conn->commit();
    $this->getUser()->setFlash('notice', 'Selected books placed');
    $this->redirect('@libro');
  }

  public function executeListCopy(sfWebRequest $request) {
    $libro = $this->getRoute()->getObject();
    $nuevoLibro = $libro->copy(true);
    $nuevoLibro->save();
    $this->getUser()->setFlash('notice', 'Libro copiado. Edite ahora la copia.');
    $this->redirect('libro_show', $nuevoLibro);
  }
}
